#include <stdio.h>
#include <string.h>
#include <math.h>

main()
{
	char s1[300],s2[300];
	
	char type[5];
	int tot,mile;
	

	scanf("%s", s1);
	while (s1[0]!='#' )
	{
		tot=0;
		while (s1[0]!='0')
		{
			scanf("%s",s2);
			scanf("%d", &mile);
			scanf("%s", type);
			if (type[0]=='F')
			{
				tot+=2*mile;
			}
			else if (type[0]=='B')
			{
				tot=tot+mile+(mile+1)/2;
			}
			else if (type[0]=='Y')
			{
				if (mile<500)
				{
					tot+=500;
				}
				else
				{
					tot+=mile;

				}
			}
			scanf("%s", s1);
		}
		printf("%d\n",tot);
		scanf("%s", s1);
	}


	return 0;
}  


